package controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.gson.Gson;

import module.OrderModule;

public class OrderController extends HttpServlet {

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/json");
		response.setCharacterEncoding("utf-8");
		PrintWriter out = response.getWriter();
		
		OrderModule orderModule=new OrderModule();
		Gson gson=new Gson();
		
		String action=request.getParameter("action");
		if(action.equals("getordermsg")){
			int userid=Integer.parseInt(request.getParameter("userid"));
			try {
				ArrayList list=orderModule.getOrderMsg(userid);
				String orderMsgjson=gson.toJson(list);
				out.print(orderMsgjson);
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		out.flush();
		out.close();
	}

}
